/**
 * Copyright(c) by JNet Smartware Group.
 * All rights reserved. Not distribution or redistribution without
 * any permission of JNet Smartware Group.
 * 
 * @author thuc
 * 2010/04/12
 */
package vn.smartware.co.framework.logging;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.jdbcplus.JDBCConnectionHandler;

import vn.smartware.co.framework.db.factory.DbResources;

/**
 * Implement a sample JDBCConnectionHandler for Oracle database
 * @author thuctt
 */
public class OracleConnectionHandler implements JDBCConnectionHandler {
	
	private Connection con = null;

	public Connection getConnection() {
		try {
			if (con != null && !con.isClosed()) {
				con.close();
			}
			DbResources dbResources = DbResources.getInstance();
			con = dbResources.getDatasource().getConnection();
			con.setAutoCommit(false);
			
		} catch (SQLException e) {
			throw new RuntimeException("SQLException.", e);
		}
		return con;
	}

	public Connection getConnection(String _url, String _username,
			String _password) {
		try {
			if (con != null && !con.isClosed()) {
				con.close();
			}
			DbResources dbResources = DbResources.getInstance();
			con = dbResources.getDatasource().getConnection();
			con.setAutoCommit(false);
			
		} catch (SQLException e) {
			throw new RuntimeException("SQLException.", e);
		}
		return con;
	}
}
